<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

$totalatrasados = 0;
$TotalPendientes = 0;
$TotalRealizados = 0;
$totalprecaucion = 0;
$Total=0;
//'Hace el request de los datos
$ban = $_REQUEST["ban"];

//'lo recibe directo del menu cuando se da el click
$OpcAdmin = $_REQUEST["OpcAdmin"];

$chkFecha = $_REQUEST["chkFecha"];
if ($chkFecha == "T")
    $checked = "checked";
else
    $checked = "";

$contador = $_REQUEST["cont"];
//'response.write(contador)
//'response.End()
$RdoCriterio = $_REQUEST["RdoCriterio"];
$txtCriterio = strtoupper($_REQUEST["txtCriterio"]);
$CboEstado = $_REQUEST["CboEstado"];
$Cboemp = $_REQUEST["Cboemp"];
$CboSoporte = $_REQUEST["CboSoporte"];
$CboEmpresa = $_REQUEST["CboEmpresa"];
$CboArea = $_REQUEST["CboArea"];
$CboCategoria1 = $_REQUEST["CboCategoria1"];
$CboCategoria2 = $_REQUEST["CboCategoria2"];
$CboCategoria3 = $_REQUEST["CboCategoria3"];
$opc = $_REQUEST["opc"];
//$CboEstado = "1"; //' Estado

if ($_REQUEST["CboEstado"] <> "")
    $CboEstado = $_REQUEST["CboEstado"];

$fecha1 = date('d/m/Y');
if ($_REQUEST["fecha1"] <> "")
    $fecha1 = $_REQUEST["fecha1"];

$fecha2 = date('d/m/Y');
if ($_REQUEST["fecha2"] <> "")
    $fecha2 = $_REQUEST["fecha2"];

//===============================================================================================================================================
//'Escoge por donde entra (Administar Tickets como usuario, tecnico o administrador)
if ($ban <> 1) {
    $checked = "checked";
    //$CboEstado = 60;
}

$join = "";
switch ($OpcAdmin) {
    case 0://' entra si es administrador del sistema
        $titulo = "Administrar Tickets";
        $opcion = 1;
        $User = "";
        break;
    case 1://'entra si es usuario
        $titulo = "Consultar Tickets Usuario";
        $opcion = 2;
        $User = " and usuario_emisor_id='" . $_SESSION["co_usua"] . "'";
        break;
    case 2://'entra si es Tecnico
        $titulo = "Bandeja de Tickets";
        $opcion = 3; //'ojo estaba 3
        if(!isset($_REQUEST["chkFecha"]))
           $chkFecha = "T";
        
        $sql0 = "select cod_dpto from tb_soporte where nu_usua = '{$_SESSION["id_usua"]}'";
        //echo $sql0;
        $cod_dpto = SoloFun_ExecSql($sql0, $Arreglo);
        //$cant_dptos_asignados = count($Arreglo);

        $join = " and b.cod_dpto = $cod_dpto";
        $User = " and b.tecnico_responsable_user='" . $_SESSION["co_usua"] . "'";
        //printArray($_SESSION);
        break;
    case 3://'entra si es Supervisor
        $titulo = "Monitorear Tickets";
        $opcion = 1;
        if(!isset($_REQUEST["chkFecha"]))
           $chkFecha = "T";
        
        $sql = "select id2 from solotb_nivel2 where co_supervisor = {$_SESSION["id_usua"]}";
        $cod_dpto = SoloFun_ExecSql($sql, $Arreglo);
        $cant_dptos_asignados = count($Arreglo);
        if($cant_dptos_asignados == 1)
            $expr = " b.cod_dpto = $cod_dpto";
        else{
            $expr = " (";
            for($i = 0; $i < $cant_dptos_asignados; $i++){
                $cod_dpto = $Arreglo[$i][0];
                $expr .= " b.cod_dpto = $cod_dpto";
                if($i < ($cant_dptos_asignados-1))
                    $expr .= " or ";
            }
            $expr .= ") ";
        }
        //$User = " and b.Administrador = {$_SESSION["id_usua"]} and $expr";
        $User = " and $expr";
        break;
    /*case 4://entra si es administrador
        $titulo = "Monitorear Tickets";
        $opcion = 1;
        $User = " and Administrador = {$_SESSION["id_usua"]}";
        break;*/
}
//printArray($_SESSION);
//'==================================================================================================================================================
$soloSQL = "select id,valor from solotb_parametros where descripcion like 'HELP DESK - ESTADO'";
soloFun_ExecSQL ($soloSQL,$SoloArrEstado);
$StrCboEstado = SoloFun_CargaCombo($SoloArrEstado,"CboEstado","",$CboEstado," style='width: 180px' class='SoloStyle_Texto'","TODOS");

$CboSoporte = $_REQUEST["CboSoporte"];
//$soloSQL2 = "select * from tb_soporte";
$soloSQL2 = "SELECT distinct co_usua, no_usua FROM solotb_usuario WHERE nodo = {$_SESSION["empresa"]} and co_usua <> 'admin' order by no_usua";
$err = 0;
soloFun_ExecSQL ($soloSQL2,$SoloArrSoporte);
$StrCboSoporte = SoloFun_CargaCombo($SoloArrSoporte,"CboSoporte","",$CboSoporte," style='width: 180px' class='SoloStyle_Texto' ","TODOS");//'OnChange='document.frm.submit()'

$Cboemp = $_REQUEST["Cboemp"];
$soloSQL3 = "select * from solotb_empresa";
soloFun_ExecSQL ($soloSQL3,$SoloArremp);
$StrCboemp = SoloFun_CargaCombo1($SoloArremp,"Cboemp","",$Cboemp," style='width: 180px' class='SoloStyle_Texto' ","TODOS");
//===============================================================================================================================================
//'carga los combos de los niveles:
//*****************************
//'N I V E L    1
//'*****************************

$soloSQL = "select * from solotb_nivel1 order by des";
soloFun_ExecSQL ($soloSQL,$SoloArrEmpresa);
//'rw "",soloSQL
//'re
if ($CboEmpresa <> "")
    $strid1 = $_REQUEST["CboEmpresa"];
else
    $strid1 = $SoloArrEmpresa[0][0];


$err = 0;
$strCboEmpresa = SoloFun_CargaCombo($SoloArrEmpresa,"CboEmpresa","",$CboEmpresa," style='width: 180px' class='SoloStyle_Texto' onChange='document.frm.opc.value=1;document.frm.submit();' ","TODOS");


//*****************************
//'N I V E L    2
//*****************************
//'rw"",strid1
//'re
$soloSQL2 = "select id2,des from solotb_nivel2 ";
$soloSQL2 .= " where id1=" . $strid1;
$soloSQL2 .= " order by des";
$err = 0;
soloFun_ExecSQL ($soloSQL2,$SoloArrArea);
//'rw "",soloSQL2
//'re
$strCboArea = SoloFun_CargaCombo($SoloArrArea,"CboArea","",$CboArea,"  style='width: 180px' class='SoloStyle_Texto' onChange='document.frm.opc.value=2;document.frm.submit();' ","TODOS");
//*****************************
//'N I V E L    3
switch ($opc) {
    case 1: //'Empresa
        $strid2 = $SoloArrArea[0][0];
        break;
    //   'rw"",strid2
    case 2:
    case 3: //'Categoria
        $strid2 = $CboArea;
        //	    'rw"",strid2
        break;
    default:
    //		'strid2=CboArea
        $strid2 = $SoloArrArea[0][0];
        break;
}
if ($strid2 == "") $strid2 = "601";

//$soloSQL3 = "select id3,des from solotb_nivel3 ";
//$soloSQL3 .= " order by des";
////echo $soloSQL3;
//soloFun_ExecSQL ($soloSQL3,$SoloArrCategoria1);
$oConexion2 = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
$soloSQL3 = "SELECT id_etdl, nombre as categoria FROM ETDL WHERE id_tdl = 28 order by nombre";
SoloFun_ExecSqlFull($soloSQL3, $SoloArrCategoria1, $oConexion2);

$strCboCategoria1 = SoloFun_CargaCombo($SoloArrCategoria1,"CboCategoria1","",$CboCategoria1," style='width: 180px' class='SoloStyle_Texto' onChange='document.frm.opc.value=3;document.frm.submit();'","TODOS");
//*****************************
//'N I V E L    4
//*****************************
switch ($opc) {
    case 1:
    case 2://'Empresa
        $strid3 = $SoloArrCategoria1[0][0];
        break;
    case 3: //'SubCategoria
        $strid3 = $CboCategoria1;
        //'rw"",strid3
        break;
    default:
    //'			strid3=CboCategoria1
        $strid3 = $SoloArrCategoria1[0][0];
        break;
}

if ($strid3 == "") $strid3 = "60103";

$soloSQL4 = "select id4,des from solotb_nivel4";
//$soloSQL4 .= " where id3=" . $strid3;
$soloSQL4 .= " order by des";

soloFun_ExecSQL ($soloSQL4,$SoloArrCategoria2);
//'StrCboCategoria2=SoloFun_CargaCombo(SoloArrCategoria2,"CboCategoria2","",CboCategoria2," style='width: 185' class='SoloStyle_Texto' onKeyDown='return tabOnEnter(this,event);'","")
//'rw"",soloSQL4
//'response.write(strid3)
//'response.End()
$strCboCategoria2 = SoloFun_CargaCombo($SoloArrCategoria2,"CboCategoria2","",$CboCategoria2," style='width: 180px' class='SoloStyle_Texto' onChange='document.frm.opc.value=3;document.frm.submit();' ","TODOS");
//*****************************
//'N I V E L    5
//*****************************
//'rw"",$_REQUEST["opc")
switch ($opc) {
    case 1:
    case 2://'Empresa
        $strid4 = $SoloArrCategoria2[0][0];
        break;
    case 3: //'SubCategoria
        $strid4 = $CboCategoria2;
        //'rw"",strid4
        break;
    default:
    //'			strid4=CboCategoria2
        $strid4 = $SoloArrCategoria2[0][0];
        break;
}

$soloSQL5 = "select id5,des from solotb_nivel5";
$soloSQL5 .= " where id4=" . $strid4;
$soloSQL5 .=  " order by des";
soloFun_ExecSQL ($soloSQL5,$SoloArrCategoria3);

if ($strid4 == "") $strid4 = "6010302";
//'StrCboCategoria3=SoloFun_CargaCombo(SoloArrCategoria3,"CboCategoria1","",CboCategoria3," style='width: 185' class='SoloStyle_Texto' onKeyDown='return tabOnEnter(this,event);'","")
//'rw"",soloSQL5
//'re
$strCboCategoria3 = SoloFun_CargaCombo($SoloArrCategoria3,"CboCategoria3","",$CboCategoria3," style='width: 180px' class='SoloStyle_Texto' ","TODOS");
//===============================================================================================================================================
//'Filtros

$strsql = "select a.id, fecha_registro, usuario_emisor_nombre, asunto, b.tecnico_responsable_nombre, b.tecnico_nombre1,
    b.estado, categoria3, categoria2, categoria1, empresa, b.cod_dpto, b.cantidad_tiempo_dias, usuario_emisor_empresa,
    b.fecha_solucion, b.fecha_expiracion, b.tipo_medida_tiempo_servicio, b.cantidad_medida_tiempo_servicio, c.des, b.fecha_asignacion";  //'agregue categoria 1 y 2
$strsql .= " from solotb_ticket a right join solotb_ticket_dpto b on a.id = b.id_ticket and b.estado is not null $join left join solotb_nivel2 c on b.cod_dpto = c.id2";
$strsql .= " where estado_registro='A' " . $User;
//'rw"",chkFecha

switch ($RdoCriterio) {
    case 1: //'por nombre de usuario
        $strsql .= " and usuario_emisor_nombre like '" . $txtCriterio . "%'";
        break;
    case 2: //'por centro No. Ticket
        $strsql .= " and a.id =  " . $txtCriterio;
        break;
    case 3: //'por Organizacion
        $strsql .= " and asunto in  (select id_tdl_datos from MIES.TDL_DATOS where campo2 like '%" . $txtCriterio . "%')";
        break;
    case 4://' todos
        $strsql = $strsql;
        break;

}

if ($RdoCriterio <> 2) {
    if ($CboSoporte <> "0" && $CboSoporte <> "")
        $strsql .= " and tecnico_responsable_user = '" . $CboSoporte . "'";

    if ($Cboemp <> "0" && $Cboemp <> "") {
        $arreglo = split(",", $Cboemp);
        $strsql .= " and usuario_emisor_empresa = '" . $arreglo[1] . "'";
    }
    if ($cboEstado == 66) {
        $comparacion = date('Y/m/d');
        $strsql .= " and fecha_expiracion < '$comparacion'";
    }else {
//        if ($CboEstado <> "1" && $CboEstado <> "")
//            $strsql .= " and b.estado = " . $CboEstado;
            //$strsql .= " and estado in (60,62)";
        if ($CboEstado <> "1" && $CboEstado <> "")
            $strsql .= " and b.estado = " . $CboEstado;
        else $strsql .= " and b.estado in (60,62,66)";

    }
    if ($CboEmpresa <> "0" && $CboEmpresa <> "")
        $strsql .= " and empresa = $CboEmpresa";

    if ($CboArea <> "0" && $CboArea <> "")
        $strsql .= " and area = $CboArea";

    if ($CboCategoria1 <> "0" && $CboCategoria1 <> "")
        $strsql .= " and categoria1 = '" . $CboCategoria1 . "'";

    if ($CboCategoria2 <> "0" && $CboCategoria2 <> "")
        $strsql .= " and Categoria2 = '" . $CboCategoria2 . "'";

    if ($CboCategoria3 <> "0" && $CboCategoria3 <> "")
        $strsql .= " and Categoria3 = '" . $CboCategoria3 . "'";

    if ($chkFecha == "")
        $strsql .= " and fecha_registro between '" . formatFecha($fecha1,"DD/MM/YYYY","YYYY-MM-DD") . " 00:00:00' and '" . formatFecha($fecha2,"DD/MM/YYYY","YYYY-MM-DD") . " 23:59:59'";
}

$orderby = $_REQUEST["orderby"];

switch ($orderby) {
    case 2: $strsql .= " order by  fecha_registro";
        break;
    case 3: $strsql .=  " order by  usuario_emisor_nombre";
        break;
    case 4: $strsql .=  " order by  empresa";
        break;
    case 5: $strsql .=  " order by  categoria3";
        break;
    case 6: $strsql .=  " order by  descripcion_solicitud1";//departamento
        break;
    case 7: $strsql .=  " order by  asunto";
        break;
    case 8: $strsql .=  " order by  tecnico_responsable_nombre";
        break;
    case 9: $strsql .=  " order by b.fecha_expiracion";
        break;
    case 10: $strsql .= " order by b.fecha_solucion";
        break;
    default: $strsql .=  " order by a.id";
        break;
}

//echo $strsql;

SoloFun_ExecSql ($strsql,$arrReq);
//SoloFun_ExecSql ($strsql,$arrReq, "ASSOC");
//printArray($arrReq);
//==============================================================================================================================================================
$promediodias = 0;
CalculaTotales();
//echo $TotalRealizados." ".$promediodias;
if($TotalRealizados > 0)
    $promediodias /= $TotalRealizados;

//'Calcula los totales de los tickets segun el estado
//=================================================================================================================================================================
function CalculaTotales() {
    global $arrReq;
    global $totalatrasados;
    global $TotalPendientes;
    global $TotalRealizados;
    global $totalprecaucion;
    global $Total;
    global $promediodias;
    $porcent = 0;
//printArray($arrReq);
    //arrReq contiene los valores mostrados en la tabla al correr la pagina
    for ($i = 0; $i < count($arrReq); $i++) {
        //'arrReq(5,1) contiene los estados asi verifica cuantos hay de cada uno y los muestra
        if ($arrReq[$i][6] == 60 || $arrReq[$i][6] == 62)
            $TotalPendientes++;
//echo $i."<br>";
        if(!is_null($arrReq[$i][15]) && $arrReq[$i][15] != "")
            $atrasado = datediff("d",$arrReq[$i][15],date('d/m/Y'));
        else $atrasado = 0;
//echo "atrasado: ".$atrasado."<br>";
        if (($arrReq[$i][6] == 60 || $arrReq[$i][6] == 62) && $atrasado > 0){
            $sql = "update solotb_ticket set estado = 66 where id = {$arrReq[$i][0]}";
            SoloFun_ExecQuery($sql);
            $totalatrasados++;
        }
//echo $totalatrasados."<br>";
//        if($arrReq[$i][15] != ""){
        if(!is_null($arrReq[$i][15]) && $arrReq[$i][15] != ""){
            $precaucion = datediff("h",$arrReq[$i][15],date('d/m/Y H:i:s'));
            $preca = datediff("d",$arrReq[$i][15],date('d/m/Y H:i:s'));
            $precaucion /= 24;
//            echo "precaucion: $precaucion<br>";
//            echo "preca: $preca<br>";
            if ($precaucion < 0) {
                /* @var $pivote1 Countable */
                $pivote1 = $precaucion*(-1);
//                echo "pivote: $pivote1<br>";
                if ($arrReq[$i][16] == 63)
                    $porcent = $arrReq[$i][17]*0.25;
            }
        
            if (($arrReq[$i][6] == 60 || $arrReq[$i][6] == 62) && (($precaucion < 0 && $pivote1 <= $porcent) || $preca == 0))
                $totalprecaucion++;
        }

        if ($arrReq[$i][6] == 61) {
            $TotalRealizados++;
            $promediodias += $arrReq[$i][12];
        }
        $Total++;
    }
    //echo "paso el primer bloque de datediff";
}
//==========================================================================================================================================
//echo $OpcAdmin;

?>
<html>
    <head>
        <title>Administrar Tickets</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/dhtmlgoodies_calendar.css" type="text/css">
        <link href="SoloStyles/Solostyles.css" rel="stylesheet" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/dhtmlgoodies_calendar.js"></SCRIPT>
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT>
        <SCRIPT type="text/JavaScript" src="Includes/ajax.js"></SCRIPT>
        <!--<link href="dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>-->
    </head>

    <body topmargin=0 marginwidth="0" marginheight="0">
        <?php include "SoloCalendar/BodyCal.php"; ?>

        <!--<form name="frm" action="solotrn_AdministrarTicket.php?ban=1" method="post">-->
        <form name="frm" action="solotrn_AdministrarTicket.php?OpcAdmin=<?php echo $OpcAdmin;?>" method="post">
            <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr><td>
                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="50%" height="16" colspan="2" class="negrita" align="center">
                                    <span class="SoloStyle_TituloPaginas"><?php echo $titulo;?></span>
                                    <br>
                                    <center>
                                        <table border='0' width='90%' cellpadding='1' cellspacing='2'>
                                            <tr>
                                                <TD colspan="2" class="boldtexto">
                                                    <table border="0" width="100%" align="center" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC">
                                                        <tr>
                                                          <td colspan="2"><!-- <img src="iconos/soloico_Nuevo.gif" border="1" alt="Nuevo Ingreso" style="cursor:hand" onClick="return SoloWindows('solotrn_Requisicion.asp?salir=1&opcion=0',100,100,860,580);"> -->
                                                                <!--<img src="iconos/soloico_buscar.gif" border="1" alt="buscar" style="cursor:hand" onClick="document.frm.opc.value=3;document.frm.submit();">-->
                                                                <img src="iconos/soloico_buscar.gif" border="1" alt="buscar" style="cursor:url" onClick="document.frm.submit();">
                                                                <input type="hidden" name="orderby" value="<?php echo $orderby;?>">
                                                                <input type="hidden" name="OpcAdmin" value="<?php echo $OpcAdmin;?>"></td>
                                                        </tr>
                                                    </table>
                                                    <table border='0' width='100%' cellpadding='1' cellspacing='1'>

                                                        <tr class="boldtexto">

                                                            <td width="20%" class="SoloStyle_Etiqueta">Subsecretar&iacute;a</td>

                                                            <td width="30%" class="SoloStyle_Grid"><?php echo $strCboEmpresa;?></td>

                                                            <td width="20%" class="SoloStyle_Etiqueta">Estado</td>

                                                            <td width="30%" class="SoloStyle_Grid"><?php echo $StrCboEstado;?></td>
                                                        </tr>
                                                        <tr class="boldtexto">

                                                            <td class="SoloStyle_Etiqueta">Departamento</td>

                                                            <td class="SoloStyle_Grid"><?php echo $strCboArea;?></td>

                                                            <td class="SoloStyle_Etiqueta">
                                                                <?php if ($OpcAdmin == 0) {?>
						Responsable
                                                                    <?php }?>
                                                            </td>

                                                            <td class="SoloStyle_Grid">
                                                                <?php if ($OpcAdmin == 0) {?><?php echo $StrCboSoporte;?><?php }?></td>

                                                        </tr>
                                                        <tr class="boldtexto">

                                                            <td width="20%" class="SoloStyle_Etiqueta">Tipo de Organizaci&oacute;n</td>

                                                            <td width="30%" class="SoloStyle_Grid"><?php echo $strCboCategoria1;?></td>

                                                            <!--<td width="20%" class="SoloStyle_Etiqueta">Empresa:</td>

                                                            <td width="30%" class="SoloStyle_Grid"><?php echo $StrCboemp;?></td>-->
                                                            <td width="20%" class="SoloStyle_Etiqueta"></td>

                                                            <td width="30%" class="SoloStyle_Grid"></td>
                                                        </tr>
                                                        <tr class="boldtexto">

                                                            <td width="20%" class="SoloStyle_Etiqueta">Tr&aacute;mite</td>

                                                            <td width="30%" class="SoloStyle_Grid"><?php echo $strCboCategoria2;?></td>

                                                            <td width="20%" class="SoloStyle_Etiqueta"></td>
                                                            <td width="30%" class="SoloStyle_Grid"></td>
                                                        </tr>
                                                        <tr class="boldtexto">
                                                            <td width="10%" class="SoloStyle_Etiqueta">Fecha</td>
                                                            <td width="40%" class="SoloStyle_Grid" colspan="3"> Desde
                                                                <input name="fecha1" type="text" class="SoloStyle_Texto"  value="<?php echo $fecha1;?>" size="12" maxlength="10" readonly="true" >
                                                                <!--<a href="javascript:ShowCalendar(document.all.dateimg1a,document.all.fecha1,null, '16/1/1999', '16/1/2010')" onClick="event.cancelBubble=true;">-->
                                                                <!--<a href="javascript:displayCalendar(document.forms[0].fecha1,'dd/mm/yyyy',this)">-->
                                                                    <img align=top border=0 id="dateimg1" src="Calendario/cal/calendar.gif" style="POSITION: relative; cursor: url" alt="calendar" onclick="displayCalendar(document.forms[0].fecha1,'dd/mm/yyyy',this)">
                                                                    <!--</a>-->
					        Hasta
                                                                <input name="fecha2" type="text" class="SoloStyle_Texto"  value="<?php echo $fecha2;?>" size="12" maxlength="10" readonly="true">
                                                                <!--<a href="javascript:ShowCalendar(document.all.dateimg1b,document.all.fecha2,null, '16/1/1999', '16/1/2010')" onClick="event.cancelBubble=true;">-->
                                                                <!--<a href="javascript:displayCalendar(document.forms[0].fecha2,'dd/mm/yyyy',this)">-->
                                                                    <img align=top border=0 id="dateimg1" src="Calendario/cal/calendar.gif" style="POSITION: relative; cursor: url" alt="calendar" onclick="displayCalendar(document.forms[0].fecha2,'dd/mm/yyyy',this)">
                                                                    <!--</a>-->
                                                                <input type="checkbox" name="chkFecha" value="T" <?php if($chkFecha == "T") echo "checked";?>>TODOS
                                                        </tr>
                                                        <tr class="boldtexto">
                                                            <td  class="SoloStyle_Etiqueta" >Criterio </td>
                                                            <td colspan="3" class="SoloStyle_Grid" > <input name="txtCriterio" type="text" class="SoloStyle_Texto" value="<?php echo $txtCriterio;?>" size="25" maxlenght="14">


                                                                <?php /*if ($OpcAdmin <> 1) {
                                                                    if ($RdoCriterio == 1)
                                                                        $checked = "checked";
                                                                    else
                                                                        $checked = "";

                                                                    ?>
                                                                <!--<input type="radio" name="RdoCriterio" value="1" <?php echo $checked;?>>
							Nombre Usuario-->
                                                                    <?php }*/
                                                                if ($RdoCriterio == 2)
                                                                    $checked = "checked";
                                                                else
                                                                    $checked = "";
                                                                ?>
                                                                <input type="radio" name="RdoCriterio" value="2" <?php echo $checked;?>>No. Ticket
                                                                <?php
                                                                if ($RdoCriterio == 3)
                                                                    $checked = "checked";
                                                                else
                                                                    $checked = "";
                                                                ?>
                                                                <input type="radio" name="RdoCriterio" value="3" <?php echo $checked;?>>Organizaci&oacute;n
                                                                <?php  if ($RdoCriterio == 4)
                                                                    $checked = "checked";
                                                                else
                                                                    $checked = "";
                                                                ?>
                                                                <input type="radio" name="RdoCriterio" value="4" onClick="document.all.txtCriterio.value=''" <?php echo $checked;?>>TODOS
                                                            </td>
                                                        </tr>

                                                    </table>
                                                </TD>
                                                <TD width = "20%" class="minitexto" colspan="2">
                                                    <table border='1' width='100%' cellpadding='1' cellspacing='0' class="SoloStyle_grid" bordercolor="#999999">
                                                        <tr>
                                                            <td> <table border='0' width='100%' cellpadding='0' cellspacing='1'>
                                                                    <tr class="SoloStyle_TextoBold">
                                                                        <td><img src="iconos/ICAtrasado.gif" width="15" height="15"></td>
                                                                        <td>Atrasados</td>
                                                                        <td><?php echo $totalatrasados;?></td>
                                                                    </tr>
                                                                    <tr class="SoloStyle_TextoBold">
                                                                        <td><img src="iconos/ICporexpirar.gif" width="15" height="15"></td>
                                                                        <td>Precauci&oacute;n</td>
                                                                        <td><?php echo $totalprecaucion;?></td>
                                                                    </tr>
                                                                    <tr class="SoloStyle_TextoBold">
                                                                        <td><img src="iconos/SoloIco_Pendientes.gif" style="border:1px solid; width: 13px; height: 13px"></td>
                                                                        <td>Pendientes</td>
                                                                        <td><?php echo $TotalPendientes;?></td>
                                                                    </tr>
                                                                    <tr class="SoloStyle_TextoBold">
                                                                        <td><img src="iconos/ICRealizado.gif" width="15" height="15"></td>
                                                                        <td>Realizados</td>
                                                                        <td><?php echo $TotalRealizados;?></td>
                                                                    </tr>
                                                                    <!--<tr class="SoloStyle_TextoBold">
                                                                        <td> </td>
                                                                        <td>Promedio dias de atenci&oacute;n</td>
                                                                        <td><?php echo round($promediodias,2);?></td>
                                                                    </tr>-->
                                                                    <tr class="SoloStyle_TextoBold">
                                                                        <td>&nbsp;</td>
                                                                        <td>Todos</td>
                                                                        <td><?php echo $Total;?></td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </TD>
                                            </tr>
                                        </table>
                                    </center>
                                    <br>
                                    <!--<TABLE border="0" width="100%" cellpadding='1' cellspacing='2'>
                                        <tr>
                                            <td style="text-align: right">
                                                <a href="">Exportar</a>
                                            </td>
                                        </tr>
                                    </TABLE>-->
                                    <TABLE border="0" width="100%" cellpadding='1' cellspacing='2'>
                                        <tr class="SoloStyle_Etiqueta">
                                            <TD width='8%' height="25" style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer" onClick="document.frm.orderby.value=1;document.frm.submit();">Ticket</span></TD>
                                            <TD width='8%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=2;document.frm.submit();"><?php if($OpcAdmin == 3){?>F. Ingreso<?php }else{echo "F. Asignaci&oacute;n";}?></span></TD>
                                            <?php if ($OpcAdmin <> 1) {?>
                                            <TD width='10%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=3;document.frm.submit();">Nombre
                                                    Usuario</span></TD>
                                                <?php }?>
                                            <!--<TD width='10%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=4;document.frm.submit();">Empresa</span></TD>-->
                                            <TD width='10%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=5;document.frm.submit();">Tipo
                                                </span></TD>
                                            <TD width='10%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=6;document.frm.submit();">Departamento</span></TD>
                                            <TD style="text-align: center"><span class="SoloStyle_TextoBold">Organizaci&oacute;n</span></TD>
                                            <?php if ($OpcAdmin <> 2) {?>
                                            <TD width='10%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=8;document.frm.submit();">Responsable</span></TD>
                                            <TD width='10%' style="text-align: center"><span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=11;document.frm.submit();">F. Asignaci&oacute;n</span></TD>
                                                <?php }?>

                                            <td width="8%" style="text-align: center"> <span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=9;document.frm.submit();">F. Expiraci&oacute;n </span></td>
                                            <td width="8%" style="text-align: center"> <span class="SoloStyle_TextoBold" style="cursor:pointer; text-align: center" onClick="document.frm.orderby.value=10;document.frm.submit();">F. Cierre </span></td>
                                        </tr>
                                        <?php
//printArray($arrReq);
                                        for ($i=0; $i < count($arrReq); $i++) {
                                            $bMarcado = false;
                                            $clase = "solostyle_pendientes";
//' obtiene las tres categorias concatenadas en una sola variable
                                            $cat1 = $arrReq[$i][9];
                                            $cat2 = $arrReq[$i][8];
                                            $cat3 = $arrReq[$i][7];

                                            //$strSQL1 = "select des,id3 from solotb_nivel3 where id3=" . $cat1;
                                            //SoloFun_ExecSQL ($strSQL1,$ArrD);
                                            $oConexion2 = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
                                                    $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
                                            $strSQL1 = "SELECT nombre,id_etdl FROM ETDL WHERE id_tdl = 28 and id_etdl = $cat1";
                                            SoloFun_ExecSQLFull ($strSQL1,$ArrD,$oConexion2);
//printArray($ArrD);
                                            $Categoria = $ArrD[0][0];
                                            if ($cat2 <> 0) {
                                                $strSQL1 = "select des,id4 from solotb_nivel4 where id4=" . $cat2;
                                                SoloFun_ExecSQL ($strSQL1,$ArrD);
                                                $Categoria .= "--" . $ArrD[0][0];
                                                if ($cat3 <> 0) {
                                                    $strSQL1 = "select des,id5 from solotb_nivel5 where id5=" . $cat3;
                                                    SoloFun_ExecSQL ($strSQL1,$ArrD);
                                                    $Categoria .= "--" . $ArrD[0][0];
                                                }
                                            }

                                            //'obtiene la descripcion de la empresa
                                            $emp = $arrReq[$i][10];
                                            $strSQL2 = "select des,id1 from solotb_nivel1 where id1=" . $emp;
                                            SoloFun_ExecSQL ($strSQL2,$ArrEmp);
                                            $Empresa = $ArrEmp[0][0];

                                            //'obtiene la descripcion del departamento
//                                            $dept = $arrReq[$i][11];
//                                            $strSQL3 = "select des,id2 from solotb_nivel2 where id2=" . $dept;
//                                            SoloFun_ExecSQL ($strSQL3,$ArrD2);
                                            //'Departamento=ArrD2(0,0)
//	   'rw"",Departamento
//	  'clase="solostyle_pendientes"
//	'Solo para probar que aparezca atrasado si supera los 5 dias el tiempo total en dias para dar solucion al ticket
                                            if(!is_null($arrReq[$i][15]) && $arrReq[$i][15] != "")
                                                $atrasado = datediff("d",$arrReq[$i][15],date('d/m/Y'));
                                            else $atrasado = 0;
                                            
                                            if (($arrReq[$i][6] == 60 || $arrReq[$i][6] == 62) && $atrasado > 0)
                                                $clase = "SoloStyle_atrasados";
                                            else {
                                                if(!is_null($arrReq[$i][15]) && $arrReq[$i][15] != ""){
//echo ":".$arrReq[$i][15].":";
                                                    $precaucion = datediff("h",$arrReq[$i][15],date('d/m/Y H:i:s'));
                                                    $preca = datediff("d",$arrReq[$i][15],date('d/m/Y H:i:s'));
                                                    $precaucion /= 24;
                                                    if ($precaucion < 0) {
                                                        $pivote1 = $precaucion*(-1);
                                                        if ($arrReq[$i][16] == 63)
                                                            $porcent = $arrReq[$i][17]*0.25;

                                                    }
//echo $precaucion;echo $clase;
                                                    if (($arrReq[$i][6] == 60 || $arrReq[$i][6] == 62) && (($precaucion < 0 && $pivote1 <= $porcent) || $preca == 0)){
                                                        $clase = "SoloStyle_precaucion";
                                                        $bMarcado = true;
                                                        //echo $arrReq[$i][6]." $precaucion $pivote1 $porcent $preca";
//                                                        if($precaucion < 0 && $pivote1 <= $porcent)
//                                                            echo "true";
//                                                        if($preca == 0)
//                                                            echo "true";
                                                        //echo " $precaucion $pivote1 $porcent $preca";
                                                    }
                                                }

                                                if(!$bMarcado){
                                                    if ($arrReq[$i][6] == 61)
                                                        $clase = "SoloStyle_realizados";
                                                    elseif($arrReq[$i][6] == 67)
                                                        $clase = "SoloStyle_entregado";
                                                    else
                                                        $clase = "solostyle_pendientes";
                                                    //'if cdate(left(arrReq(0,i),10))<>date and arrReq(7,i) = 1 then
                                                    //'  clase="solostyle_atrasados"
                                                }
                                            }
                                            ?>
                                        <tr class="<?php echo $clase;?>">
                                            <TD>
                                                <a href="javascript:SoloWindows('solotrn_IngresarTicketUsuario.php?IdTicket=<?php echo $arrReq[$i][0];?>&opcion=<?php echo $opcion;?>&cat1=<?php echo $arrReq[$i][9];?>&cat2=<?php echo $arrReq[$i][8];?>&cat3=<?php echo $arrReq[$i][7];?>&area=<?php echo $arrReq[$i][11];?>&asunto=<?php echo $arrReq[$i][3];?>',200,100,900,450,'');">
                                                    <img src="iconos/soloico_consultar.gif" border="0" alt="consultar" style="cursor:hand" onClick="SoloWindows('solotrn_IngresarTicketUsuario.php?IdTicket=<?php echo $arrReq[$i][0];?>&opcion=<?php echo $opcion?>&cat1=<?php echo $arrReq[$i][9];?>&cat2=<?php echo $arrReq[$i][8];?>&cat3=<?php echo $arrReq[$i][7];?>&area=<?php echo $arrReq[$i][11];?>&asunto=<?php echo $arrReq[$i][3];?>',200,100,900,450,'');">
                                                    <?php echo $arrReq[$i][0];?>
                                                </a>
                                            </TD>
                                            <TD><?php
                                                if($OpcAdmin == 3){
                                                    //fecha de ingreso
                                                    $f2 = trim($arrReq[$i][1]);
//'f2=formatfecha(f2,"MM/DD/YYYY","DD-MMM-YYYY")
                                                    
                                                }else{
                                                    //fecha de Asignacion
                                                    $f2 = trim($arrReq[$i][19]);
                                                }
                                                if(!empty($f2)){
                                                    $f2 = getArrFromDate($f2, "-");
                                                    echo date("d/m/Y H:i:s", getTimestampFromArray($f2, "Y-m-d"));
                                                }
                                                ?>
                                            </TD>
                                            <?php if ($OpcAdmin <> 1) { //nombre usuario?>
                                                <TD><?php echo $arrReq[$i][2];?></TD>
                                            <?php }?>
                                            <!--<TD><?php echo $arrReq[$i][13]; //empresa?></TD>-->
                                            <TD><?php echo $Categoria; //tipo?></TD>
                                            <TD><?php echo $arrReq[$i][18];?></TD>
                                            <TD><?php
                                            $sql = "SELECT campo2 FROM TDL_DATOS T WHERE id_tdl_datos = {$arrReq[$i][3]}"; //asunto
                                            //echo $sql;
                                            $oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
                                                    $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
                                            $oConexion->EjecutarQuery($sql);
                                            $arrOrganizaciones = $oConexion->getData("NUM");
                                            $oConexion->liberarResultado();
                                            $oConexion->Cerrar();
                                            echo $arrOrganizaciones[0][0];
                                            //echo $arrReq[$i][3]; //asunto?></TD>
                                                <?php if ($OpcAdmin <> 2) {?>
                                            <TD ><?php echo $arrReq[$i][4];?></TD>
                                            <TD ><?php 
                                            $f1 = trim($arrReq[$i][19]);
//'f1=formatfecha(f1,"MM/DD/YYYY","DD-MMM-YYYY")
                                                        if(!empty($f1)){
                                                            $f1 = getArrFromDate($f1, "-");
                                                            echo date("d/m/Y H:i:s", getTimestampFromArray($f1, "Y-m-d"));
                                                        }
                                            ?></TD>
                                            <?php }?>
                                            <td>
                                                        <?php
//'response.write formatFecha(arrReq(15,i),"YYYY-MM-DD","DD/MMM/YYYY")
//'response.write arrReq(15,i)
                                                        $f1 = trim($arrReq[$i][15]);
//'f1=formatfecha(f1,"MM/DD/YYYY","DD-MMM-YYYY")
                                                        if(!empty($f1)){
                                                            $f1 = getArrFromDate($f1, "-");
                                                            echo date("d/m/Y H:i:s", getTimestampFromArray($f1, "Y-m-d"));
                                                        }
                                                        ?> </td>
                                            <td><?php
                                            if(!empty($arrReq[$i][14])){
                                                $fec_cierre = getArrFromDate($arrReq[$i][14], "-");
                                                echo date("d/m/Y H:i:s", getTimestampFromArray($fec_cierre, "Y-m-d"));
                                                //echo FormatFecha($arrReq[$i][14],"YYYY/MM/DD","DD-MMM-YYYY");
                                            }?> </td>
                                        </tr>
                                            <?php
                                        }
                                        ?>
                                    </TABLE>

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>

            <input name="opc" type="hidden">
        </form>
        <?php  if ($ban <> 1) { ?>
        <script type="text/javascript">
            //document.frm.opc.value=3;
            //document.frm.submit();
        </script>
            <?php  }?>

    </body>
</html>
